unit RecordProc;

interface

procedure AddToBegin(head : pelement, num : integer);
procedure PrintList(head : pelement);
procedure DelFromBegin(head : pelement);
procedure AddToEnd(head : pelement, num : integer);
procedure DelFromEnd(head : pelement);

implementation

procedure AddToBegin(head : pelement, num : integer);
var
  tmp : head;
begin
  tmp := head;
  new(head);
  head^.value := num;
  head^.next := tmp;
end;
procedure PrintList(head : pelement);
var
  current : pelement;
begin
  current := head;
  while (current <> nil) then
  begin
    writeln(current^.value);
    current := current^.next;
  end;
end;
procedure DelFromBegin(head : pelement);
var
  temp : pelement;
begin
  if (head <> nil) then
  begin
    head :=  head^.next;
    temp := head^.next;
    dispose(head);
    head := tmp;
  end;
  if (head^.next = nil) then
  begin
    temp := nil;
    dispose(head);
    head := tmp;
  end;
end;
procedure AddToEnd (head :  pelement; num : integer);
var
  current : pelement;
begin
  if (head <> nil) then
  begin
    current := head;
    while (current^.next <> nil) do
    begin
       current := current^.next;
       new(current^.next);
       current^.next^.value := num;
       current^.next^.next := nil;
    end;
  end
  else
  AddToBegin(head, num);
end;
procedure DelFromEnd(head : pelement);
var
  current : pelement;
begin
  if (head <> nil) then
  begin
    current := head;
    while (current^.next <> nil) do
      current := current^.next;
    dispose(current^.next);
    current := nil;
  end;
end;
end.
 